#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int n,k,r[N],a[N],ans;
map<int,bool> vis;
bool ok()
{
	for(int i = 1;i<=n;i++)
		if(a[i]>r[i]) return 0;
		else if(a[i]<r[i]) return 1;
	return 1;
}
void dfs(int x,int las,int sum)
{
	if(x>n)
	{
		if(ok())
		{
			if(vis[sum]==0) ans++;
			vis[sum] = 1;
		}
		return;
	}
	for(int i = las;i<k;i++)
		a[x] = i,dfs(x+1,i,sum*k+i);
}
signed main()
{
	freopen("count.in","r",stdin);
	freopen("count.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>k;
	for(int i = 1;i<=n;i++)
		cin>>r[i];
	vis[0] = 1;
	dfs(1,0,0);
	cout<<ans;
	return 0;
}

